/*
============================================================================
Name        : IGMSLogger.h
Author      : Peter Wang
Version     :
CreateDate	: 2007-9-12
Copyright   : 
Description : You can use this class to log your application.
1.Copy igmslogger.dll to "\sys\bin\IGMSLogger.dll".
2.Create a folder at c:\\data\\(your application name).
============================================================================
*/


#ifndef __Logger_H__
#define __Logger_H__

#include <f32file.h>
//#ifndef _DEBUG
#define RELEASE_LOG 0//if 1, we have logging (also) in release build 
//#endif


const TInt KMaxLogEntrySize = 2048;

#if RELEASE_LOG
	#define LOGCLOSE            CLogger::Close()
#ifdef __SERIES60_3X__
	#define LOGARG(txt,parm...) {_LIT8(KTxt, txt); CLogger::Write(KTxt, parm);}
#else
	#define LOGARG(txt,parm) {_LIT8(KTxt, txt); CLogger::Write(KTxt, parm);}
#endif
	#define LOGTXT(txt)         {_LIT8(KTxt, txt); CLogger::Write((const TDesC8&)KTxt);}
	#define LOGDES8(des)        CLogger::Write((const TDesC8&)des);
	#define LOGDES16(des)       CLogger::Write(des);
	#define LOGERR(txt,err)     if (err) LOGARG(txt, err)
	#define LOGCALL(exp)        {LOGARG("Calling \"%s\"", #exp); exp; LOGARG("Call to \"%s\" passed.", #exp);}
	#define LOGENTER            LOGARG("%s start", __PRETTY_FUNCTION__)
	#define LOGEXIT             LOGARG("%s end", __PRETTY_FUNCTION__)
	#define LOGMEM(ptr)         LOGARG("%s [0x%x]", #ptr, (TUint)ptr)
#else 
	#define LOGCLOSE            
#ifdef __SERIES60_3X__
#define LOGARG(txt,parm...) 
#else
#define LOGARG(txt,parm) 
#endif
	
	#define LOGTXT(txt)        
	#define LOGDES8(des)     
	#define LOGDES16(des)      
	#define LOGERR(txt,err)   
	#define LOGCALL(exp)        exp;
	#define LOGENTER           
	#define LOGEXIT             
	#define LOGMEM(ptr)       
#endif 

class CLogger : public CBase
{
public:
	/*IMPORT_C*/ static void Write(const TDesC8& aText);
	/*IMPORT_C*/ static void Write(const TDesC16& aText);
	/*IMPORT_C*/ static void Write(TRefByValue<const TDesC8> aFmt,...);
	/*IMPORT_C*/ static void Close();

private:
	CLogger();
	~CLogger();
	TBool Construct();
	static CLogger* Logger();
	void DoWrite();
	TBool GetLogFileNameWithoutExt(TDes& aFileName);

private:
	RFs                     iFs;
	RFile                   iFile;
	TBuf8<KMaxLogEntrySize> iLogBuffer;
};

#endif	// __Logger_H__
